<?php

namespace App\utils;

/**
 * aes加密与解密工具
 * User: 姚鸿杰
 * Date: 2019/4/12
 * Time: 20:40
 */
class AesUtils
{
    private static $iv = 'yaohongjie970101';

    /**
     * 加密方法
     * @param string $str
     * @return string
     */
    public static function encrypt($str, $pws)
    {
        //AES, 128 ECB模式加密数据
        $encrypted = openssl_encrypt($str, 'AES-128-CBC',
            $pws, OPENSSL_RAW_DATA, self::$iv);
        return base64_encode($encrypted);
    }

    /**
     * 解密方法
     * @param string $str
     * @return string
     */
    public static function decrypt($str, $pws)
    {
        //AES, 128 ECB模式加密数据
        $decrypt = openssl_decrypt(base64_decode($str), 'AES-128-CBC',
            $pws, OPENSSL_RAW_DATA, self::$iv);
        return $decrypt;
    }
}
